Page({
  data: {
    data:[],
    noConnect:false,
    isDelete:false
  },

  onLoad: function (options) {
    var that = this
    var userinfo = wx.getStorageSync('userinfo')
    wx.request({
      url: getApp().globalData.url+'mine/',
      data:{
        type:"favorite",
        openid:userinfo.openid
      },
      success:function(res){
        var newData=[];
        var target = res.data
        var question = wx.getStorageSync("question_data")

        for(var i=0  ;i<target.length;i++){
          target[i]
          newData.push(question[target[i]-1])
        }
        newData.reverse()
      that.setData({
        data:newData
      })
    },
      fail:function(res){
        that.setData({
          noConnect:true
        })
      }
    })
  },
  detele:function(e){
    var that = this
    var openid = wx.getStorageSync("userinfo").openid

    wx.request({
      url: getApp().globalData.url+"mine",
      data:{
        type:"delete_favorite",
        openid:openid,
        id:e.currentTarget.id
      },
      success:function(res){
        that.onLoad()
      }
    })
  },
  redirect:function(e){
    var id = e.currentTarget.id
    wx.navigateTo({
      url:"/pages/demo4/demo4?id="+id
    })
  },
  www:function(e){
    var that = this
    if(that.data.isDelete){
      that.setData({
        isDelete:false
      })
    }else if (!that.data.isDelete){
      that.setData({
        isDelete:true
      })
    }
  }

})